﻿
@{
    ViewData["Title"] = "List";
}

@section Scripts
    {
    <link href="~/css/page.css" rel="stylesheet" />
    <script type="text/html" id="barAction">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script type="text/javascript">
        var selfLayer = null, page = 1, active = null;
        layui.use(['layer', 'table', 'laydate', 'treeSelect'], function () {
            var layer = layui.layer //弹层
                ,
                table = layui.table, form = layui.form, treeSelect = layui.treeSelect; //表格
            var start = null;
            var end = null;

            var obj = new Date();
            year = obj.getFullYear();
            month = obj.getMonth() + 1;
            console.log(month);

            layui.laydate.render({
                elem: '#vardateTime'
                , type: 'month'
                , value: year + "-" + month
            });

            console.log("123545" + localStorage.getItem("X-AreCode"));

            //地区
            treeSelect.render({
                // 选择器
                elem: '#varProjectName',
                // 数据
                data: '/MarketPrice/GetAreaTreeAll?name=' + localStorage.getItem("X-AreCode"),
                // 请求头
                //  headers: { 'Authorization': 'Bearer ' + localStorage.getItem("X-TOKEN") },

                // 异步加载方式：get/post，默认get
                type: 'get',
                // 占位符
                placeholder: '地区',
                // 是否开启搜索功能：true/false，默认false
                search: true,
                // 一些可定制的样式
                style: {
                    folder: {
                        enable: true
                    },
                    line: {
                        enable: true
                    }
                },
                // 点击回调
                click: function (d) {
                    console.log(d);
                },
                // 加载完成后的回调函数
                success: function (d) {
                    console.log(d);
                    //                选中节点，根据id筛选
                    treeSelect.checkNode('varProjectName', 3);

                    // console.log($('#varProjectName').val());

                    //                获取zTree对象，可以调用zTree方法
                    var treeObj = treeSelect.zTree('varProjectName');
                    console.log(treeObj);

                    //                刷新树结构
                    treeSelect.refresh('varProjectName');
                }
            });

            //鱼种
            treeSelect.render({
                // 选择器
                elem: '#varFishName',
                // 数据
                data: '/MarketPrice/GetFishTreeAll',
                // 请求头
                //  headers: { 'Authorization': 'Bearer ' + localStorage.getItem("X-TOKEN") },
                // 异步加载方式：get/post，默认get
                type: 'get',
                // 占位符
                placeholder: '淡水鱼类',
                // 是否开启搜索功能：true/false，默认false
                search: true,
                // 一些可定制的样式
                style: {
                    folder: {
                        enable: true
                    },
                    line: {
                        enable: true
                    }
                },
                // 点击回调
                click: function (d) {
                    console.log(d);
                },
                // 加载完成后的回调函数
                success: function (d) {
                    console.log(d);
                    //                选中节点，根据id筛选
                    treeSelect.checkNode('varFishName', 3);

                    // console.log($('#varProjectName').val());

                    //                获取zTree对象，可以调用zTree方法
                    var treeObj = treeSelect.zTree('varFishName');
                    console.log(treeObj);

                    //                刷新树结构
                    treeSelect.refresh('varFishName');
                }
            });

            //执行一个 table 实例
            table.render({
                id: 'dataList',
                elem: '#dataview',
                height: 'full-80',
                url: "/MarketPrice/MarketPriceAll"
                , where: { areCode: localStorage.getItem("X-AreCode") }
                , request: {
                    pageName: 'index' //页码的参数名称，默认：page
                    , limitName: 'size' //每页数据量的参数名，默认：limit
                }
                , parseData: function (res) { //res 即为原始返回的数据
                    console.log(res);
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.total, //解析数据长度
                        "data": res.result.data //解析数据列表
                    };
                },
                response: {
                    statusCode: 200 //规定成功的状态码，默认：0
                },
                done: function (res, curr, count) {
                    page = curr;
                },
                page: true,
                cols: [
                    [
                        { field: 'userName', title: '报价单位' },
                        { field: 'fishName', title: '鱼种名称' },
                        { field: 'averagePrice', title: '鱼种均价(元)' },
                        { field: 'description', title: '规格' },
                        { field: 'price', title: '规格单价(元)' },
                        { field: 'marketName', title: '所属市场' },
                        { field: 'address', title: '市场地址' },
                        { field: 'createTime', title: '录入时间', width: 180, filter: { type: 'date[yyyy-MM-dd]' }, sort: true },
                        // { fixed: 'right', width: '10%', title: '操作', align: 'center', toolbar: '#barAction' }
                    ]
                ]
            });

            var $b = layui.$;
            active = {
                reload: function (page) {
                    //执行重载
                    table.reload('dataList', {
                        page: {
                            curr: page || 1 //重新从第 1 页开始
                        },
                        where: {
                            sasearch: $("#keyword").val(),
                            areName: $("#varProjectName").val(),
                            fishName: $("#varFishName").val(),//
                            dateMonth: $("#vardateTime").val(),
                            dataType: $("#dataType").val(),
                            areCode: localStorage.getItem("X-AreCode")
                        }
                    });
                }
            };
            $b('#search').on('click', function () {
                var type = $b(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

        });
    </script>
}

<blockquote class="layui-elem-quote layui-text layui-form">
    <div class="layui-inline">
        <label class="layui-form-label">关键字：</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="keyword" name="keyword" style="width:240px" placeholder="">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">地区：</label>
        <div class="layui-input-inline">
            <input type="text" id="varProjectName" lay-filter="tree" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">鱼种：</label>
        <div class="layui-input-inline">
            <input type="text" id="varFishName" lay-filter="tree" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">数据来源：</label>
        <div class="layui-input-inline">
            <select id="dataType" name="dataType" lay-filter="dataType" autocomplete="off">
                <option value="">全部</option>
                <option value="App直报">App直报</option>
                <option value="鱼价格数据导入">鱼价格数据导入</option>
            </select>
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">月份：</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="vardateTime" name="vardateTime" style="width:240px" placeholder="yyyy-MM-dd">
        </div>
    </div>

    <div class="layui-inline">
        <div class="layui-form-label">
            <button class="layui-btn" id="search" style="width: 60px; height: 28px; line-height: 28px; display: inline" data-type="reload">搜索</button>
        </div>
    </div>
</blockquote>
<table class="layui-hide" id="dataview" lay-filter="datalist"></table>

